CC = gcc # define the C/C++ compiler to use
CFLAGS = -O3 -Wall -Wall -Wextra -pedantic -fPIC
# define any directories containing header files other than /usr/include
INCLUDES = -Iinclude/
# define the C++ source files
SRCS = src/c_api.cpp src/User_Parameter.cpp src/NN_data.cpp src/Indata.cpp src/Loss_generator.cpp src/Gradient_generator.cpp src/Gradient_generator_fullcal.cpp src/Gradient_generator_fullcal_par20.cpp src/Gradient_generator_fullcal_approx.cpp src/Gradient_generator_fullcal_sample_grad.cpp src/Gradient_estimator.cpp src/Gradient_estimator_CV.cpp src/Gradient_estimator_RB.cpp
# define the C/C++ object files 
# This uses Suffix Replacement within a macro:
#   $(name:string1=string2)
#         For each word in 'name' replace 'string1' with 'string2'
OBJS = $(SRCS:.c=.o)
# define the shared library name
TARGET = lib_POF.so

.PHONY: clean
    
all:    $(TARGET)
	@echo  Successfully compiled a .so library.

# compile object file to .so shared library
$(TARGET): $(OBJS) 
	$(CC) $(CFLAGS) $(INCLUDES) -shared -o $(TARGET) $(OBJS) 

# compile source files to object files

# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file) 
# (see the gnu make manual section about automatic variables)
.c.o:
	$(CC) $(CFLAGS) $(INCLUDES) -cpp $<  -o $@
clean:
	$(RM) *.o 